package com.health.db.dao.order.impl;

import java.util.List;

import com.health.db.dao.ServiceInterface;
import com.health.db.dao.order.IRegisterOrderZScheduleDao;
import com.health.db.mapper.RegisterOrderZScheduleMapper;
import com.health.db.model.RegisterOrderZSchedule;
import com.health.db.model.RegisterOrderZScheduleTemp;
import com.health.db.model.UserLIST;
import com.health.db.model.UserLISTExt;
import com.health.redis.RedisConstants;

public class RegisterOrderZScheduleDaoImpl extends ServiceInterface implements IRegisterOrderZScheduleDao{
	
	private RegisterOrderZScheduleMapper registerOrderZScheduleMapper;

	String  selectByAccepterId=":accepterId:";
	String  selectByOrderTimeSolt=":orderTimeSolt:";
	String  scheduleDate=":scheduleDate:";
	String  createDate=":createDate:";
	String selectByStuffId=":stuffId:";
	@Override
	public int insert(RegisterOrderZSchedule record) {
		// TODO Auto-generated method stub
		return registerOrderZScheduleMapper.insert(record);
	}

	public RegisterOrderZScheduleMapper getRegisterOrderZScheduleMapper() {
		return registerOrderZScheduleMapper;
	}

	public void setRegisterOrderZScheduleMapper(
			RegisterOrderZScheduleMapper registerOrderZScheduleMapper) {
		this.registerOrderZScheduleMapper = registerOrderZScheduleMapper;
	}
	
	
	@Override
	public int updateByPrimaryKeySelective(RegisterOrderZSchedule record) {
		// TODO Auto-generated method stub
		return registerOrderZScheduleMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public int countScheduleSize(RegisterOrderZSchedule record) {
		// TODO Auto-generated method stub
		
		getRedisOperatiorLogic();
	
		String key =RedisConstants.RegisterOrderZScheduleMapper+selectByAccepterId+record.getRegisterid()
				+selectByOrderTimeSolt+record.getOrderTimeSolt()+scheduleDate+record.getScheduleDate()
				+createDate+record.getCreateDate();
		
		Object object=null;
		Integer size = null;
		try
		{
			if(redisOperatiorLogic.isJedisIsConnected())
			{	
				//get data from redis
				object = redisOperatiorLogic.readObject(key, getPublicRedisGroupNo("1"));
			 }
		     if(null!=object&&!object.equals("")){
		    	 size =  (Integer) object;
			
		     }else{
			 
			
			  size= registerOrderZScheduleMapper.countScheduleSize(record);
			  if(redisOperatiorLogic.isJedisIsConnected())
				{redisOperatiorLogic.setEx(key, size,  getOrderRedisGroupNo("1"));}
			 }
	           
		} catch (Exception e) {
			      e.printStackTrace();
		}
		
		return size;
	}

	@Override
	public List<RegisterOrderZScheduleTemp> selectByStuffId(Long stuffId){
		// TODO Auto-generated method stub
		
		 List<RegisterOrderZScheduleTemp> list =  null;

			getRedisOperatiorLogic();
			
			String key =RedisConstants.RegisterOrderZScheduleMapper+selectByStuffId+stuffId;
			
			Object object=null;
			Integer size = null;
			try
			{
				if(redisOperatiorLogic.isJedisIsConnected())
				{	
					//get data from redis
					object = redisOperatiorLogic.readObject(key, getPublicRedisGroupNo("1"));
				 }
			     if(null!=object&&!object.equals("")){
			    	 list =  (List<RegisterOrderZScheduleTemp>) object;
				
			     }else{
				 
				
			    	 list =registerOrderZScheduleMapper.selectByStuffId(stuffId);
				  if(redisOperatiorLogic.isJedisIsConnected())
					{redisOperatiorLogic.setEx(key, size,  getOrderRedisGroupNo("1"));}
				 }
		           
			} catch (Exception e) {
				      e.printStackTrace();
			}
			
			
			
			
			return list;
	}

	/**
	 * 
	 * orderTimeSolt 时间节点
	 */
	@Override
	public List<RegisterOrderZScheduleTemp> selectByAllStuffId(Integer orderTimeSolt) {
		// TODO Auto-generated method stub
		List<RegisterOrderZScheduleTemp> list = null;
		
		
		
		getRedisOperatiorLogic();
		
		String key =RedisConstants.RegisterOrderZScheduleMapper+selectByOrderTimeSolt+orderTimeSolt;
		
		Object object=null;
		Integer size = null;
		try
		{
			if(redisOperatiorLogic.isJedisIsConnected())
			{	
				//get data from redis
				object = redisOperatiorLogic.readObject(key, getPublicRedisGroupNo("1"));
			 }
		     if(null!=object&&!object.equals("")){
		    	 list =  (List<RegisterOrderZScheduleTemp>) object;
			
		     }else{
			 
			
		    	 list =  registerOrderZScheduleMapper.selectByAllStuffId( orderTimeSolt);
			  if(redisOperatiorLogic.isJedisIsConnected())
				{redisOperatiorLogic.setEx(key, size,  getOrderRedisGroupNo("1"));}
			 }
	           
		} catch (Exception e) {
			      e.printStackTrace();
		}
		
		
		
		
		return list;
	}
	
 
}
